/*
 * @Author: c
 * @Date: 2024-01-09 12:24:20
 * @LastEditTime: 2024-02-07 11:16:27
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\album\dto\create-album.dto.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Transform, Type } from "class-transformer";
import { IsArray, IsDate, IsEnum, IsNumber, IsOptional, IsString, IsUrl, ValidateNested } from "class-validator";
import { LangEnum } from "src/common/enums";
import { Artist } from "../../artist/entities/artist.entity";
import { Song } from "../../song/entities/song.entity";

export class CreateAlbumDto { }

export class Pic {

  @IsUrl({ host_whitelist: ['localhost', 'img01.dmhmusic.com'] }, { message: "专辑封面路径格式不正确" })
  url: string;

  @IsString({ message: "文件id必填" })
  id: string
}

export class AlbumForm {

  @IsOptional()
  id?: number

  //专辑唯一代码（P10004217236）
  @IsOptional()
  albumAssetCode: string;

  //专辑介绍
  @IsOptional()
  @IsString()
  introduce: string;


  //封面图
  @IsOptional()
  @ValidateNested()
  @Type(() => Pic)
  pic: Pic;

  //专辑标题
  @IsOptional()
  @IsString()
  title: string;

  //专辑分类（流行）
  @IsOptional()
  @IsNumber()
  genre?: number;

  //发行日期
  @Transform(v => new Date(v))
  @IsDate()
  releaseDate: Date;
  //下架时间
  @Transform(v => new Date(v))
  @IsDate()
  downTime: Date;
  //上架时间
  @Transform(v => new Date(v))
  @IsDate()
  pushTime: Date;
  //语言
  @IsEnum(LangEnum, { message: "语言格式不正确" })
  lang: LangEnum;


  //专辑中歌曲列表
  songList: Song[];
  @IsOptional()
  @IsNumber({ allowNaN: false }, { message: "专辑中歌曲的id必须为数字", each: true })
  songIds: number[];

  //所属的歌手列表
  artist: Artist[];
  /**
   * 歌手ID列表
   */
  @IsArray({ message: "歌手id格式不是数组格式" })
  @IsNumber({ allowNaN: false }, { message: "歌手id格式不正确", each: true })
  artistIds: number[];
}

export class FavoriteForm {
  @IsNumber()
  id: number;
}